package vip.websky.project.common.utils;

/**
 * 公用工具类
 *
 * @author: YangYong
 * @TIME 2017/6/15-17:32
 */

import java.util.Random;


/**
 * <ul>
 * <li>1.将手机号码 脱敏</li>
 * <li>2.生成指定长度的随机数。</li>
 * </ul>
 */
public class CommonUtils {


    private static char [] numbersAndLetters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
    private static char [] numbers = "0123456789".toCharArray();
    /**
     * 1.将手机号码加密  替换中间四位为 *
     * @param phoneNum      需要加密的号码
     * @return 加密后手机号 eg: 131****7601
     */
    public static String encryptPhoneNum(String phoneNum){
        return phoneNum.substring(0, 3) + "****" + phoneNum.substring(7, 11);
    }

    /**
     * 2.生成指定长度的随机数。
     * @param length 随机数长度
     * @return
     */
    public static String generatorRandom(int length){
        StringBuffer result = new StringBuffer();
        if (length<1){
            return "";
        }
        for (int i=0; i<length;i++){
            result.append(numbersAndLetters[new Random().nextInt(numbersAndLetters.length)]);
        }

        return result.toString();
    }

    /**
     * 3.生成指定长度的随机数子编号。
     * @param length 随机数长度
     * @return
     */
    public static String generatorRandomNumber(int length){
        StringBuffer result = new StringBuffer();
        if (length<1){
            return "";
        }
        for (int i=0; i<length;i++){
            result.append(numbers[new Random().nextInt(numbers.length)]);
        }

        return result.toString();
    }

    public static void main(String [] arg0){

        String a = "1.00";
        System.out.println(Long.parseLong(a));
    }

}
